﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using InterLinq.Base;
using Sebarf.Core.Interfaces;
using Sebarf.Diagnostics.Interfaces;
using Sebarf.Utils.Interfaces;

#endregion

namespace Sebastof.ProcessChains.ProcessSteps {
	/// <summary>
	/// Description of the class
	/// </summary>
	public class CachedOriginalDataCollection : CachedOriginalDataBase<IEnumerable> {
		#region Public Methods

		public CachedOriginalDataCollection(IServiceLocatorService context)
			: base(context, context.GetRegisteredService<IChangeTrackingCacheService>()) {
		}

		public CachedOriginalDataCollection() {
		}

		protected override IEnumerable OnProcess(IEnumerable toProcess) {
			foreach (object o in toProcess) {
				try {
					IObjectHierarchyFlattenerService hf = ObjectHierarchyFlattenerService;
					hf.FieldInfoLookup = m_FieldInfos;
					List<object> col = hf.Flatten(o);
					foreach (object oflat in col) {
						PrepareForType(oflat.GetType());
						AddObjectData(oflat);
					}
				}
				catch (Exception ex) {
					Check.AssertException(false, ex.Message);
					throw;
				}
			}

			return base.OnProcess(toProcess);
		}

		#endregion
	}
}